//
//  UIViewExt.swift
//  Yip
//
//  Created by 周智水 on 2022/5/29.
//  Copyright © 2022 yip.com. All rights reserved.
//

import Foundation
import UIKit

extension UIActivityIndicatorView {
    var isActive: Bool {
        get { isAnimating }
        set {
            if newValue {
                startAnimating()
            } else {
                stopAnimating()
            }
        }
    }
    
    func toggle() {
        isActive.toggle()
    }
}

extension UIViewController {
    
    func dismissToRoot() {
        var vc: UIViewController? = self
        while let p = vc?.presentingViewController {
            p.dismiss(animated: true)
            vc = p
        }
    }
}
